FUNCTION

assert_events

function assert_events(expected: (text, gtv)...): unit

Assert that the given events were emitted during the construction of the last block, in the specified order.

Events are emitted in application code using op_context.emit_event().

Example - single event:

Application code
operation main() {
    op_context.emit_event("my_message_type", "my_data".to_gtv());
}
Test code
function test_main() {
    main().run();

    // Assertion passes
    rell.test.assert_events(("my_message_type", "my_data".to_gtv()));
}

function test_main_bad_1() {
    main().run();

    // Assertion fails - wrong message type
    rell.test.assert_events(("other_message_type", "my_data".to_gtv()));
}

function test_main_bad_2() {
    main().run();

    // Assertion fails - wrong message content
    rell.test.assert_events(("my_message_type", "other_data".to_gtv()));
}

Example - multiple events:

Application code
operation main() {
    op_context.emit_event("my_message_type", "my_data".to_gtv());
    op_context.emit_event("other_message_type", "other_data".to_gtv());
}
Test code
function test_main() {
    main().run();

    // Assertion passes
    rell.test.assert_events(
        ("my_message_type", "my_data".to_gtv()),
        ("other_message_type", "other_data".to_gtv())
    );
}

function test_main_bad() {
    main().run();

    // Assertion fails - event order incorrect
    rell.test.assert_events(
        ("other_message_type", "other_data".to_gtv()),
        ("my_message_type", "my_data".to_gtv())
    );
}

To assert a subset of events, or to assert independently of event order, use rell.test.get_events() and make assertions over elements of the returned list.

Parameters

  • expected — expected event sequence

See Also

  1. op_context.emit_event() - Rell Standard Library
  2. rell.test.get_events() - Rell Standard Library

Since

0.13.0

© 2026 Chromia